package codeRandomThoughts.Test513找树左下角的值;

import codeRandomThoughts.utils.TreeNode;

//二刷 递归
public class Solution3 {

    //全局变量 方便计算
    int bottomLeftValue = 0;
    int maxDepth = 0;

    public int findBottomLeftValue(TreeNode root) {
        findValue(root, 1);
        return bottomLeftValue;
    }

    public void findValue(TreeNode node, int depth) {
        //终止条件
        if (node == null) return;

        //根
        if (depth > maxDepth) {
            maxDepth = depth;
            bottomLeftValue = node.val;
        }

        //这里其实简化了一个回溯的过程
        findValue(node.left, depth + 1);
        findValue(node.right, depth + 1);
    }
}
